Integration with org-link

Backlink: ยง2020-04-17-1605 Expansions HUB

For further integration with org-mode, we can create a new type of link. Let’s call it zdlink.

Links should be formatted like so: [[zdlink:2020-04-17-1605][link]]. Which results in the following .

Please note: Deft should be loaded for this to work.

First, we define org-link parameters.

(org-link-set-parameters
  "zdlink"
  :follow (lambda (str) (zetteldeft--search-filename (zetteldeft--lift-id str)))
  :complete 'efls/zd-complete-link
  :help-echo "Searches provided ID in zetteldeft")

This tells org about a new type of link and what to do with it: find a zetteldeft ID in the link string, and search for it.

This means that the link will work as long as there is a zetteldeft-id-regex in it, which implies that this, too, will work: [[zdlink:2020-04-17-1605 Expansions HUB.org][link]].

To tell Zetteldeft to (almost) always insert these Org styled links, set the variable zetteldeft-insert-link-function to zetteldeft-insert-link-org-style.

For convenience, we can also create a small completion function to facilitate inserting links with the org-insert-link function.

(defun efls/zd-complete-link ()
  "Link completion for `zdlink' type links"
  (let* ((file (completing-read "File to link to: "
                (deft-find-all-files-no-prefix)))
         (link (zetteldeft--lift-id file)))
     (unless link (user-error "No file selected"))
     (concat "zdlink:" link)))

Now when org-insert-link is called, simply select zdlink from the list, and a completion window will pop up.